<?php
class modsinglecontent extends CI_Model{
	var $singlecontent = "single_content";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_content,$id_menu,$title_content,$date_content,$container_content,$file_upload,$enable)
	{
		$this->id_content= $id_content;
		$this->id_menu= $id_menu;
		$this->title_content= $title_content;
		$this->date_content= $date_content;
		$this->container_content= $container_content;
		$this->file_upload= $file_upload;
		$this->enable= $enable;
	}
	
	function getList($page,$uri_segment){
		$this->db->select('*');
		$this->db->from('single_content');
		$this->db->join('setting_menu', 'setting_menu.id_menu = single_content.id_menu', 'left');
		$this->db->limit($page); 
		$query = $this->db->get();
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{		
		$arrayData = array(
			'id_content'=>$this->id_content,
			'id_menu'=>$this->id_menu,
			'title_content'=>$this->title_content,
			'date_content'=>$this->date_content,
			'container_content'=>$this->container_content,
			'file_upload'=>$this->file_upload,
			'enable'=>$this->enable
		);
		return $this->db->insert($this->singlecontent, $arrayData);
	}
	
	function update($id_content)
	{
		$arrayData = array(
			'id_menu'=>$this->id_menu,
			'title_content'=>$this->title_content,
			'date_content'=>$this->date_content,
			'container_content'=>$this->container_content,
			'file_upload'=>$this->file_upload,
			'enable'=>$this->enable
		);
		$this->db->where('id_content', $id_content);
		return $this->db->update($this->singlecontent, $arrayData);
	}
        
	function remove($id_content)
	{
		$this->db->where('id_content', $id_content);
		return $this->db->delete($this->singlecontent);
	}	
	
	function detail($id_content)
	{
		$this->db->where('id_content', $id_content);
		$query = $this->db->get($this->singlecontent);	
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('title_content',$name);
		$query = $this->db->get($this->singlecontent);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getSingleContent($id_menu)
	{
		$this->db->where('id_menu', $id_menu);
		$query = $this->db->get($this->singlecontent);	
		return $query->result_array();
	}
	
	function getDetailContent($id_content)
	{
		$this->db->where('id_content', $id_content);
		$query = $this->db->get($this->singlecontent);	
		return $query->result_array();
	}
}
?>